﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using System.Runtime.InteropServices;

namespace dataSend.ToolForm
{
    public partial class PortSet : DevComponents.DotNetBar.Office2007Form
    {
        private MainForm mf = null;
        private string csDevId = "";
        private short iType = 0;
        private string str = "";
        public PortSet(string str, string csDevId, short iType, MainForm mf)
        {
            InitializeComponent();
            this.str = str;
            this.mf = mf;
            this.csDevId = csDevId;
            this.iType = iType;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            short result = mf.vsOcx.SetComParamEx(csDevId, iType, int.Parse(cboBaudrate.SelectedItem.ToString()), int.Parse(cboDataBit.SelectedItem.ToString()), int.Parse(cboStopBit.SelectedItem.ToString()), int.Parse(cboParity.SelectedItem.ToString()));

            if (result >= 0)
            {
                DialogResult dr = MessageBox.Show("保存成功！", "系统提示");
                if (dr == DialogResult.OK)
                {
                    this.Close();
                }
            }
            else
            {
                MessageBoxEx.Show("保存失败！", "系统提示");
            }

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void PortSet_Load(object sender, EventArgs e)
        {
            if (str.Contains(","))
            {
                string[] results = str.Split(',');
                this.cboBaudrate.Text = results[0];
                this.cboDataBit.Text = results[1];
                this.cboStopBit.Text = results[2];
                this.cboParity.Text = results[3];
            }
        }

        private void PortSet_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Dispose(true);
        }
    }
}
